package com.yedean.mall.config;

import com.yedean.mall.token.TokenClientProperties;
import com.yedean.mall.token.TokenGenerator;
import com.yedean.mall.token.TokenRedisClient;
import com.yedean.mall.token.TokenUtilMd5Generator;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * TokenClientConfig
 *
 * @author yedean
 * @date 2022/8/17
 */
@Configuration
@EnableConfigurationProperties({TokenClientProperties.class})
public class TokenClientConfig {
    
    @Bean
    public TokenRedisClient tokenRedisClient(TokenClientProperties properties, RedisTemplate<String,Object> redisTemplate){
        String namespace = properties.getRedisNamespace();
        long accessTokenExpiration = properties.getAccessTokenExpiration();
        long refreshTokenExpiration = properties.getRefreshTokenExpiration();
        TokenGenerator generator = new TokenUtilMd5Generator();
        
        return new TokenRedisClient(namespace,redisTemplate,generator,accessTokenExpiration,refreshTokenExpiration);
    }
}
